﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DemoObject;
using BusinessObjects;
using HTT.Utility;

public partial class Module_News_Controls_ItemNewsDetail : System.Web.UI.UserControl
{
    public string NewsTextId { get; set; }
    public string CategoryName { get; set; }
    public string CategoryTextId { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            if (Request["NewsTextId"] != null)
                NewsTextId = Request["NewsTextId"].ToString();
            if (Request["CategoryTextId"] != null)
                CategoryTextId = Request["CategoryTextId"].ToString();
            HashSet<string> hs = new HashSet<string>();
            IList<TblNews> ls = TblNewsRepository.CreateInstant().SelectListItem(null, null, NewsTextId, "", "", "", null, null, null, hs);
            if (ls != null && ls.Count > 0)
            {
                ls[0].Views += 1;
                SetTitle(ls[0]);
                //update view
                TblNewsRepository.CreateInstant().Update(ls[0]);
                CategoryName = ls[0].TblCategory.Name;
                rpt.DataSource = ls;
                rpt.DataBind();
                hs.Add("CreatedDate DESC");
                int count = 0;
                ls = TblNewsRepository.CreateInstant().SelectListItem(null, ls[0].CategoryId, "", "", "", "", true, null, null, 1, 20, out count, hs);
                rptmore.DataSource = ls;
                rptmore.DataBind();
            }

        }
    }
    void SetTitle(TblNews _item)
    {
        string title = _item.Title;
        string description = HTT.Utility.UnicodeConversion.CreateInstant().GetTextFromHtml(_item.Summary);
        string keywords = _item.Title;
        MasterPage _page = this.Page.Master;
        WebUtility.SetPage(title, description, keywords, _page);
    }
}
